﻿<?php
class nav
{
	private $built = array(
							"nav" => false,
							);
	function nav()
	{
		Global $mySql, $lib;
		$this->mySql = $mySql;
		$this->lib = $lib;
	}
	function buildMessageBox()
	{	
		$this->prefs = $this->Login["prefs"];
		$opts['prefs']['everyone'] = $this->prefs['display']['Everyone'];
		$opts['prefs']['reply'] = $this->prefs['display']['Reply'];
		$opts['prefs']['home'] = $this->prefs['display']['Home'];
		
		$opts['sort'] = lib::returnField("sort");
		
		$opts['time']['time1'] = lib::returnField("time1");
		$opts['time']['time2'] = lib::returnField("time2");
		
		// Get the Message Data
		// Previous Message Data can be found in the $this->lastRequest Array ("query", "data", "length")
		$data = db_messages::getMessages($opts);
		$this->buildMessages($data);
		//$this->buildLeftInfo();
	}
	function buildNavBar()
	{
		if(!$this->built['nav'])
		{
			display::Header();
			display::navBar($this->Login);
			$this->built['nav'] = true;
		}
	}
	private function buildMessages($data)
	{
		$prefs = $this->Login["prefs"]["display"];
			if($prefs['Home'])
			{
				$home = "CHECKED ";
			}
			else
			{
				$home = "";
			}
			if($prefs['Everyone'])
			{
				$everyone = "CHECKED ";
			}
			else
			{
				$everyone = "";
			}
			if($prefs['Reply'])
			{
				$reply = "CHECKED ";
			}
			else
			{
				$reply = "";
			}
			
		?>
		<div id=box>
			<div id=editbox>
				<span id="inputbox">
					<form name=form action="javascript:insertMessage();" method=post>
						<textarea rows=5 cols=50 name="form[message]" style="background-image: url(textbox.jpg);" id=textbox></textarea>
						<span class=button>
							<input type=submit value="Post">
						</span>
						</form>
				</span>
			</div>
			<div class=messagebody style="background-image: url(background.jpg);">
				<div id=home>
					<ul>
						<li class=topbuttons style="text-align: center;">
						<span style="width: 60%; border-bottom: 2px solid #FF9900;">
							Feed:
							<input type=checkbox <?php echo $home ?>onChange=updateFeed('Home')> Home - 
							<input type=checkbox <?php echo $reply ?>onChange=updateFeed('Reply')> Reply -
							<input type=checkbox <?php echo $everyone ?>onChange=updateFeed('Everyone')> Everyone
							<button onclick=refreshNow();>Hi!</button>
						</span>
						</li>
						<div class=message><ul class=messagebody style=""><?php
			if($data != false)
			{
				$num = 1;
				foreach($data as $key => $entry)
				{	
					echo "<li id=home".$num." class=everyone>";
					display::FullMsg($entry);
					echo "</li>";
					$num++;
				}
			}
			else
			{
				echo "<li><center><i> There are no Messages to Display </i></center></li>";
			}
		?>
		</div>
		</ul>
		</div>
		</div>
		</div>
		<?php	
	}
	private function buildLeftInfo()
	{
		?>
		<div id=leftinfo>
			<h1>Welcome to Twicha,</h1>
			<Br>Twicha is a messaging service that allows you to...
			<ul>
			<li> Send Messages </li>
			<li> Connect with Friends </li>
			<li> Rate Messages</li>
			<li> Find what others liked most </li>
			<li> Reply to friends by putting the @ sign infront of their username</li>
			<li> Virtually Never have to refresh when viewing messages!</li>
			</ul>
			<br>
			To Get Started, Click <a href="users?list=top"> Here </a> to see some of the popular people on Twicha!<br>
			<br>
			<h1> Quick Tips </h1><br>
			If you want a quick and dirty version of how Twicha works, you've came to right place.
			In short, the entire left message box is controlled by javascript, and will refresh every 30 seconds.
			To check how long untill the next refresh, click the down arrow at the bottom.
		<h1> Twicha Developer Updates </h1><br>
		Hey,<br>
		<br>
		Chacha Here! I'm glad you've found my little website. I had a lot of problems with 
		both FriendFeed and Twitter, so I decided to create a web application that would combine
		a messaging system hosted on my own database, an AJAX UI, and a bunch of features I would have liked to see on some other
		systems.
		</div>
		<?php
	}
	function buildFooter($action="")
	{
		if(!EMPTY($action))
		{
			echo "<script language=javascript> requestHandler('".$action."') </script>";
		}
		?>
		</body>
		</html>
		<?php
	}
	function buildUserControl()
	{
		?>
			<div id=firstbox>
				Welcome to the Twicha User Control Panel. Here you can quickly edit all of your user settings, friend options, and unblock people you have blocked.
			</div>
		<?php
	}
	public function setLoginData($data)
	{
		$this->Login = $data;
		$this->LoginStatus = true;
	}

}
?>